package com.tanjun.thirdservice.web;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.io.*;

public class Test {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\1.txt");
        StringBuilder json = new StringBuilder();
        String tempString = null;
        BufferedReader reader = reader = new BufferedReader(new FileReader(file));
        while ((tempString = reader.readLine()) != null) {
            json.append(tempString.trim());
        }
        reader.close();

        int count=1;
        JSONObject jsonObject = JSON.parseObject(json.toString());
        JSONArray array = jsonObject.getJSONObject("data").getJSONArray("list");
        for (int i = 0; i < array.size(); i++) {
            JSONArray array2 = array.getJSONObject(i).getJSONArray("article_list");
            for (int k = 0; k < array2.size(); k++) {
                String title = array2.getJSONObject(k).getJSONObject("article")
                        .getString("title")
                        .replace("|","-")
                        .replaceAll(" ","")
                        .replace(":","-")
                        .replace("：","-")
                        .replaceAll("/","")
                        .replace("\"","")
                        .replace("?","")
                        .replace("？","")
                        ;
                //System.out.println(count+"  "+title);
                if(count>=48 &&count<=122){
                    changeName(title,count);
                }
                count++;
            }
        }
    }

    private static void changeName(String title,int index){
        String prx="01 Spring课程介绍 - 极客时间 企业版_chunk_"+(index-1)+".mp4";
        String path="D:\\study\\Spring学习资料\\Spring全家桶\\";
        File file=new File(path+prx);
        if(file.exists()){
           File file1= new File(path+title+".mp4");
           if(file1.exists()){
               return;
           }
         //System.out.println("ren "+prx+"    "+title+".mp4");
           if(file.renameTo(file1))
            System.out.println("ren "+prx+"    "+title+".mp4");
           else {
               System.out.println("失败 "+prx+"    "+title+".mp4");
           }
        }
    }
}
